package com.xhwl.logistics.converter;

import com.xhwl.common.pojo.cent.vehicle.VehcPayRecord;
import com.xhwl.logistics.bo.VehiclePayRecordBO;
import com.xhwl.logistics.bo.VehiclePayRecordStayTimeBO;
import com.xhwl.logistics.component.VehicleHomeAddressProperty;
import com.xhwl.logistics.enums.VehicleCardTypeEnum;
import com.xhwl.logistics.util.AboutDateUtil;
import com.xhwl.logistics.vo.VehiclePayRecordVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

//@Component
public class ToVehiclePayRecordVO {

    @Autowired
    private VehicleHomeAddressProperty vehicleHomeAddressProperty;

    public VehiclePayRecordVO toVehiclePayRecordVO(VehcPayRecord vehcPayRecord) {
        VehiclePayRecordVO vehiclePayRecordVO = new VehiclePayRecordVO();

        BeanUtils.copyProperties(vehcPayRecord, vehiclePayRecordVO);

        //缴费记录实体类的改变，plateNumber属性改为了plateNo
//        vehiclePayRecordVO.setHomeAddress(vehicleHomeAddressProperty.getHomeAddress(vehcPayRecord.getPlateNumber().substring(0, 2)));
        vehiclePayRecordVO.setHomeAddress(vehicleHomeAddressProperty.getHomeAddress(vehcPayRecord.getPlateNo().substring(0, 2)));

        //修改
//        vehiclePayRecordVO.setStaySecond(3000);

        return vehiclePayRecordVO;
    }

    //修改
//    public List<VehiclePayRecordVO> toVehiclePayRecordVOList(List<VehcPayRecord> list) {
//        return list.stream().map(this::toVehiclePayRecordVO).collect(Collectors.toList());
//    }

    public VehiclePayRecordVO toVehiclePayRecordVO(VehiclePayRecordBO vehiclePayRecordBO) {
        VehiclePayRecordVO vehiclePayRecordVO = new VehiclePayRecordVO();

        BeanUtils.copyProperties(vehiclePayRecordBO, vehiclePayRecordVO, "cardType", "payTime", "vehiclePayRecordStayTimeBO", "totalMoney", "paidMoney", "freeMoney");

        Integer cardType = vehiclePayRecordBO.getCardType();
        if (null==cardType) {
            vehiclePayRecordVO.setCardType(VehicleCardTypeEnum.TEMPORARILY.getDescription());
        } else {
            vehiclePayRecordVO.setCardType(VehicleCardTypeEnum.toVehicleCardTypeEnum(cardType).getDescription());
        }

        vehiclePayRecordVO.setPayTime(AboutDateUtil.dateToString(vehiclePayRecordBO.getPayTime()));

        VehiclePayRecordStayTimeBO vehiclePayRecordStayTimeBO = vehiclePayRecordBO.getVehiclePayRecordStayTimeBO();
        if (null!=vehiclePayRecordStayTimeBO) {
            vehiclePayRecordVO.setStayTime(vehiclePayRecordStayTimeBO.toStayTimeString());
        } else {
            vehiclePayRecordVO.setStayTime("/");
        }

        vehiclePayRecordVO.setTotalMoney(vehiclePayRecordBO.totalMoneyString());
        vehiclePayRecordVO.setPaidMoney(vehiclePayRecordBO.paidMoneyString());
        vehiclePayRecordVO.setFreeMoney(vehiclePayRecordBO.freeMoneyString());

        return vehiclePayRecordVO;
    }

    public List<VehiclePayRecordVO> toVehiclePayRecordVOList(List<VehiclePayRecordBO> list) {
        return list.stream().map(this::toVehiclePayRecordVO).collect(Collectors.toList());
    }

}
